package com.atguigu;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.LinkedList;

public class Main {

	/*
	 * 开发一个简单错误记录功能小模块，能够记录出错的代码所在的文件名称和行号。 处理:
	 * 1.记录最多8条错误记录，对相同的错误记录(即文件名称和行号完全匹配)只记录一条，错误计数增加； (文件所在的目录不同，文件名和行号相同也要合并)
	 * 2.超过16个字符的文件名称，只记录文件的最后有效16个字符；(如果文件名不同，而只是文件名的后16个字符和行号相同，也不要合并)
	 * 3.输入的文件可能带路径，记录文件名称不能带路径
	 * 
	 * 输入描述:
	 * 
	 * 一行或多行字符串。每行包括带路径文件名称，行号，以空格隔开。
	 * 
	 * 文件路径为windows格式
	 * 
	 * 如：E:\V1R2\product\fpgadrive.c 1325
	 * 
	 * 
	 * 
	 * 输出描述:
	 * 
	 * 将所有的记录统计并将结果输出，格式：文件名代码行数数目，一个空格隔开，如: fpgadrive.c 1325 1
	 * 
	 * 结果根据数目从多到少排序，数目相同的情况下，按照输入第一次出现顺序排序。
	 * 
	 * 如果超过8条记录，则只输出前8条记录.
	 * 
	 * 如果文件名的长度超过16个字符，则只输出后16个字符
	 * 
	 * 
	 * 输入例子:
	 * 
	 * E:\V1R2\product\fpgadrive.c 1325
	 * 
	 * 
	 * 输出例子:
	 * 
	 * fpgadrive.c 1325 1
	 */

	public static void main(String[] args) throws Exception {
		InputStreamReader inputStreamReader = new InputStreamReader(System.in);
		BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
		String readLine = null;
		LinkedList<Node> linkedList = new LinkedList<>();
		int order=0;
		while ((readLine = bufferedReader.readLine()) !=null) {
			String[] split = readLine.split(" ");
			String[] fileNames = split[0].split("\\\\");
			int num = Integer.parseInt(split[1]);
			String fileName = fileNames[fileNames.length - 1];
			String lastFileName = null;
			if (fileName.length() > 16) {
				lastFileName = fileName.substring(fileName.length() - 16);
			} else {
				lastFileName = fileName;
			}
			int index = 0;
			for (Node node : linkedList) {
				
				if (node.getFileName().equals(fileName) && node.getNum() == num) {
					node.countPlus();
				
					sort(linkedList,index);
					break;
				}
				index++;
			}
			if (index >= linkedList.size()) {
				order++;
				Node node = new Node(fileName, lastFileName, num,order);
				linkedList.add(node);
			}
		}
		
		if (linkedList.size() > 8) {
			for (int i = 0; i < 8; i++) {
				Node node = linkedList.get(i);
				System.out.println(node);
			}
		}else{
			for (Node node : linkedList) {
				System.out.println(node);
			}
		}
	}

	private static void sort(LinkedList<Node> linkedList,int index) {
		int size=linkedList.size();
		for (int i = index; i>0; i--) {
				if(linkedList.get(i).getCount()>linkedList.get(i-1).getCount()){
					Node temp=linkedList.get(i);
					linkedList.set(i, linkedList.get(i-1));
					linkedList.set(i-1,temp);
			}
				if(linkedList.get(i).getCount()==linkedList.get(i-1).getCount()){
					if(linkedList.get(i).getOrder()<linkedList.get(i-1).getOrder()){
						Node temp=linkedList.get(i);
						linkedList.set(i, linkedList.get(i-1));
						linkedList.set(i-1,temp);
					}
				}
		}
	}

	public static class Node {

		private String fileName;
		private String lastFileName;
		private int num;
		private int count = 1;
		private int order;
		
		public Node(String fileName, String lastFileName, int num,int order) {
			this.order=order;
			this.num = num;
			this.fileName = fileName;
			this.lastFileName = lastFileName;
		}

		public Node() {
		}

		public int getOrder() {
			return order;
		}

		public void setOrder(int order) {
			this.order = order;
		}

		public int getNum() {
			return num;
		}

		public void setNum(int num) {
			this.num = num;
		}

		public String getFileName() {
			return fileName;
		}

		public void setFileName(String fileName) {
			this.fileName = fileName;
		}

		public String getLastFileName() {
			return lastFileName;
		}

		public void setLastFileName(String lastFileName) {
			this.lastFileName = lastFileName;
		}

		public int getCount() {
			return count;
		}

		public void setCount(int count) {
			this.count = count;
		}

		public void countPlus() {
			count++;
		}

		public String toString() {
			return lastFileName + " " + num + " " + count;
		}

	}
}
